<template>
  <van-button
    :icon="value === 1 ? 'good-job' : 'good-job-o'"
    :class="{ text: value === 1 }"
    :loading="loading"
    @click="changeLike"
  />
</template>

<script>
// 导入 收藏 取消收藏 接口
import { clickLike, cancleClickLike } from '@/api/user.js'
export default {
  name: 'clickLike',
  props: {
    value: {
      type: Number,
      required: true
    },
    art_id: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      loading: false,
      status: 0
    }
  },
  created() {},
  methods: {
    async changeLike() {
      this.loading = true
      try {
        console.log(this.value)
        if (this.value === 1) {
          // 表示 已经收藏
          await cancleClickLike(this.art_id)
        } else {
          //   表示 没有收藏
          await clickLike(this.art_id)
        }
        this.$emit(
          'input',
          this.value === 1 ? (this.status = -1) : (this.status = 1)
        )
        this.$toast.success(this.value === 1 ? '我将继续努力' : '感谢喜欢')
      } catch (err) {}
      this.loading = false
    }
  },
  computed: {},
  watch: {},
  components: {}
}
</script>

<style lang="less" scoped>
.text {
  color: #ffbf1a;
}
</style>
